//
//  WPlanHomeVC.m
//  WKMaybell
//
//  Created by 何文虎 on 2018/12/4.
//  Copyright © 2018年 何文虎. All rights reserved.
//

#import "WPlanHomeVC.h"
#import "WKPlanBookListVC.h"
#import "WKPlanBookCollectVC.h"
#import "WKSubmitBookVC.h"
#import "JXCategoryView.h"

@interface WPlanHomeVC ()<JXCategoryViewDelegate,UIScrollViewDelegate>
@property(nonatomic,strong)UIScrollView *scrollView;
@property(nonatomic,strong)JXCategoryTitleView *categoryView;
@end

@implementation WPlanHomeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"计划";
   [self initViews];
}


- (void)initViews{
    self.view.backgroundColor = [UIColor whiteColor];
    self.naviBar.leftBtn.hidden = YES;
    // 添加所有子控制器
    [self setUpAllViewController];
   
    self.naviBar.title = @"我的日记";
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame  = CGRectMake(ScreenWidth-60-12, StatusBarHeight, 60, 44);
    [rightBtn setTitle:@"创建日记" forState:UIControlStateNormal];
    [rightBtn setTitleColor: UIColorFromHex(0x3c3c3c) forState:UIControlStateNormal];
    rightBtn.titleLabel.font = PFSC_MediumFont(15);
    [rightBtn addTarget:self action:@selector(rightAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.naviBar addSubview:rightBtn];
    
//    [self.naviBar.rightBtn setTitle:@"创建日记" forState:UIControlStateNormal];
//    [self.naviBar.rightBtn setTitleColor: UIColorFromHex(0x3c3c3c) forState:UIControlStateNormal];
//    self.naviBar.rightBtn.titleLabel.font = PFSC_MediumFont(15);
}



-(void)setUpAllViewController{
    
    [self.childViewControllers makeObjectsPerformSelector:@selector(removeFromParentViewController)];
    
    NSArray *titles = @[@"日记", @"收藏日记"];
    
    CGFloat  categoryViewHeight = 44;
    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, NavBarHeight+categoryViewHeight, ScreenWidth, ScreenHeight-NavBarHeight-44)];
    self.scrollView.delegate = self;
    self.scrollView.pagingEnabled = YES;
    self.scrollView.contentSize = CGSizeMake(ScreenWidth*2, 0);
    self.scrollView.bounces = NO;
    [self.view addSubview:self.scrollView];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    if (@available(iOS 11.0, *)) {
        self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    
    WKPlanBookListVC *bookListVC = [[WKPlanBookListVC alloc] init];
    [self addChildViewController:bookListVC];
    bookListVC.view.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight-NavBarHeight-categoryViewHeight);
    [self.scrollView addSubview:bookListVC.view];
    
    WKPlanBookCollectVC *collectVC = [[WKPlanBookCollectVC alloc] init];
    collectVC.view.frame = CGRectMake(ScreenWidth, 0, ScreenWidth, ScreenHeight-NavBarHeight-categoryViewHeight);
    [self addChildViewController:collectVC];
    [self.scrollView addSubview:collectVC.view];
    
    self.categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, NavBarHeight, ScreenWidth, categoryViewHeight)];
    self.categoryView.titles = titles;
    self.categoryView.backgroundColor = [UIColor whiteColor];
    self.categoryView.delegate = self;
    self.categoryView.titleSelectedColor = BACK_COLOR;
    self.categoryView.titleColor = UIColorFromHex(0x3C3C3C);
    self.categoryView.titleFont = PFSC_MediumFont(13);
    self.categoryView.titleColorGradientEnabled = NO;
    self.categoryView.titleLabelZoomEnabled = YES;
    
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorLineViewColor = BACK_COLOR;
    lineView.indicatorLineWidth = 35;
    self.categoryView.indicators = @[lineView];
    self.categoryView.contentScrollView = self.scrollView;
    
    [self.categoryView addSubview:[WHFactory addLineWithFrame:CGRectMake(0, categoryViewHeight-1, ScreenWidth, 1)]];
    
    [self.view addSubview:self.categoryView];
    
}

#pragma mark - 创建日记
- (void)rightAction:(UIButton*)sender{
    WKSubmitBookVC *submintVC = [[WKSubmitBookVC alloc]init];
    submintVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:submintVC animated:YES];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
